package com.henry.xman.util

import com.intellij.openapi.ui.Messages

/**
 * Date  2022/8/30.
 * Author henry.jia
 * Description
 */
object CommonUtil {

    @JvmStatic
    fun showMsgTip(msg: String, title: String? = null) {
        Messages.showMessageDialog(
            String(msg.toByteArray(), Charsets.UTF_8), title ?: "提示", Messages.getInformationIcon()
        )
    }

    /**
     * 区分平台获取protoc的绝对路径
     */
    fun findProtocCmd(): Array<String> {
        return if (System.getProperty("os.name").contains("Mac")) {
            getOsCommand("which protoc")
        } else {
            getOsCommand("where protoc")
        }
    }

    /**
     * Linux("Linux"),Mac_OS("Mac OS"),Mac_OS_X("Mac OS X"),Windows("Windows")
     */
    fun getOsCommand(command: String): Array<String> {
        return if (System.getProperty("os.name").contains("Linux")) {
            //linux
            arrayOf("bash", "-c", command)
        } else if (System.getProperty("os.name").contains("Mac")) {
            //mac
            arrayOf("/bin/bash", "-c", command)
        } else {
            //windows
            arrayOf("cmd", "/c", command)
        }
    }
}